package com.yonyou.pmclouds.team.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.project.entity.ProjectConst;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.team.entity.TeamMemberVO;
import org.apache.commons.lang3.StringUtils;

public class TeamMemberDeleteCheck implements SingleProcessor<TeamMemberVO> {
    private ProjectSimpleQuery query;

    public TeamMemberDeleteCheck(ProjectSimpleQuery query) {
        this.query = query;
    }

    @Override
    public void process(TeamMemberVO vo, TeamMemberVO orig) throws BusinessException {
        if (orig == null) {
            return;
        }
//        if (orig.getUserRole() == TeamMemberVO.UserRoleConst.ROLE_MANAGER) {
//            throw new BusinessException("项目经理不可移除出项目团队！");
//        }
        ProjectVO project = query.queryProject(orig.getPkProject());
        if (StringUtils.isNotEmpty(project.getManager()) && project.getManager().equals(orig.getPkUser())) {
            throw new BusinessException("项目经理不可移除出项目团队！");
        }
        if (project.getProjectState() == ProjectConst.STATE_END) {
            throw new BusinessException("已经结束的项目，不可再操作项目团队！");
        }
    }
}
